package com.qwiki.content;

import java.util.regex.Pattern;

public class AdhocTextFilter implements StringFilter {
  public static Pattern badPattern = Pattern.compile("");

  @Override
  public String[] filter(String[] strings) {
    if (strings == null) return null;
    boolean[] check = new boolean[strings.length];
    int count = 0;
    for (int i = 0; i < strings.length; i++) {
      // get rid of bad ones
      if (isGood(strings[i].toLowerCase())) {
        count++;
        check[i] = true;
      }
    }
    String[] ret = new String[count];
    count = 0;
    for (int i = 0; i < strings.length; i++) {
      if (check[i]) {
        ret[count] = strings[i];
        count++;
      }
    }
    return ret;
  }

  @Override
  public boolean isGood(String string) {
    return !badPattern.matcher(string.toLowerCase()).find();
  }

  public static void main(String[] args) {
    String[] tests = new String[]{
        "asdf19lj",
        "story_county",
        "List_sdfad",
        "o_lists",
        "children of aaa",
        "computer_science"
    };
    String[] filtered = new AdhocTextFilter().filter(tests);
    for(String test : filtered) {
      System.out.println(test);
    }
  }
}
